<?php
session_start();
$SESSION = $_SESSION['SESSION'];
if(!isset($SESSION)){
header("location:login.php");
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Admin Catoira-García</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<style media="all" type="text/css">@import "css/all.css";</style>
</head>
<body>
<div id="main">

 	<div id="header">
    
		<a href="index.html" class="logo"><img src="img/logo.gif" width="101" height="29" alt="" /></a>
		<ul id="top-navigation">
			<li class="active"><span><span>Propiedades</span></span></li>
			<li><span><span><a href="adminfotos.php">Fotos</a></span></span></li>
			<li><span><span><a href="adminnoticias.php">Noticias</a></span></span></li>
			<li><span><span><a href="#">Usuarios</a></span></span></li>
			<li><span><span><a href="#">Statistics</a></span></span></li>
			<li><span><span><a href="#">Design</a></span></span></li>
			<li><span><span><a href="#">Contents</a></span></span></li>
		</ul>
	</div>
	<div id="middle">

<?php
echo '<div style="text-align:right"><strong>';
echo $SESSION['nombre'].' ';
echo $SESSION['apellido'];
echo ' (';
echo $SESSION['login'];
echo')';
echo'  |  ';
echo ' <a href="logout.php">Salir</a>';
echo '</strong></div>'

?>
                        <div id="center-column">
			<div class="top-bar">
				
				<h1>Propiedades</h1>
				<div class="breadcrumbs">Administración de propiedades de Catoira-García</div>
			</div><br />
		  <div class="select-bar">

		  </div>
			<div class="table">
				<img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
				<!--<img src="img/bg-th-right.gif" width="8" height="7" alt="" class="right" />-->
				<table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="177">ID</th>
                                                <th>Tipo</th>
						<th>Dirección</th>
                                                <th>Dormitorios</th>
						<th>Baños</th>
						<th>Ambientes</th>
						<th>Garage</th>
						<th>Patio</th>
						<th>Quincho</th>
                                                <th>Terreno</th>
                                                <th>Barrio</th>
                                                <th>Localidad</th>
                                                <th>En Alquiler</th>
                                                <th>En Venta</th>
                                                <th>Alquiler</th>
                                                <th class="last">Valor</th>
					</tr>

            <?php

            //Limito la busqueda
            $TAMANO_PAGINA = 10;

            //examino la página a mostrar y el inicio del registro a mostrar
            @$pagina = $_GET["pagina"];
            if (!$pagina) {
            $inicio = 0;
            $pagina=1;
            }
            else {
            $inicio = ($pagina - 1) * $TAMANO_PAGINA;
            }





            include 'conexionbd.php';

            $result = mysql_query("SELECT * FROM propiedad ORDER BY id", $link);

            //numero total de registros
            $num_total_registros = mysql_num_rows($result);
            //calculo el total de páginas
            $total_paginas = ceil($num_total_registros / $TAMANO_PAGINA);

            $result = mysql_query("SELECT * FROM propiedad ORDER BY id LIMIT ".$inicio.",".$TAMANO_PAGINA, $link);

            while ($row=mysql_fetch_array($result))
            {
            echo '<tr>';
            if ($row['selected']==0)/*Aca van las filas que no se publican*/
            {
            echo '<td><center>'.$row['id'].'</center></td>';
            echo '<td><center>'.$row['tipo'].'</center></td>';
            echo '<td><center>'.$row['direccion'].'</center></td>';
            echo '<td><center>'.$row['dormitorios'].'</center></td>';
            echo '<td><center>'.$row['banos'].'</center></td>';
            echo '<td><center>'.$row['ambientes'].'</center></td>';
            echo '<td><center>'.$row['garage'].'</center></td>';
            echo '<td><center>'.$row['patio'].'</center></td>';
            echo '<td><center>'.$row['quincho'].'</center></td>';
            echo '<td><center>'.$row['terreno'].'</center></td>';
            echo '<td><center>'.$row['barrio'].'</center></td>';
            echo '<td><center>'.$row['localidad'].'</center></td>';
            if ($row['enalquiler']==1){
                echo '<td><center>Sí</center></td>';
            }
            else {
                echo '<td><center>No</center></td>';
            }

            if ($row['enventa']==1){
                echo '<td><center>Sí</center></td>';
            }
            else {
                echo '<td><center>No</center></td>';
            }
            echo '<td><center>'.$row['alquiler'].'</center></td>';
            echo '<td><center>'.$row['precio'].'</center></td>';
            echo '</tr>';

            } /*Aca van las filas que se publican*/

            else{

               echo '<td class="selected"><center>'.$row['id'].'</center></td>';
            echo '<td class="selected"><center>'.$row['tipo'].'</center></td>';
            echo '<td class="selected"><center>'.$row['direccion'].'</center></td>';
            echo '<td class="selected"><center>'.$row['dormitorios'].'</center></td>';
            echo '<td class="selected"><center>'.$row['banos'].'</center></td>';
            echo '<td class="selected"><center>'.$row['ambientes'].'</center></td>';
            echo '<td class="selected"><center>'.$row['garage'].'</center></td>';
            echo '<td class="selected"><center>'.$row['patio'].'</center></td>';
            echo '<td class="selected"><center>'.$row['quincho'].'</center></td>';
            echo '<td class="selected"><center>'.$row['terreno'].'</center></td>';
            echo '<td class="selected"><center>'.$row['barrio'].'</center></td>';
            echo '<td class="selected"><center>'.$row['localidad'].'</center></td>';
            if ($row['enalquiler']==1){
                echo '<td class="selected"><center>Sí</center></td>';
            }
            else {
                echo '<td class="selected"><center>No</center></td>';
            }

            if ($row['enventa']==1){
                echo '<td class="selected"><center>Sí</center></td>';
            }
            else {
                echo '<td class="selected"><center>No</center></td>';
            }
            echo '<td class="selected"><center>'.$row['alquiler'].'</center></td>';
            echo '<td class="selected"><center>'.$row['precio'].'</center></td>';
            echo '</tr>';


            }
            
            
            
            }

	    echo '</table>';
            echo '<form name="form1" method = "GET" action="adminpropiedades.php">';
            echo '<div class="select" >';
            echo '<strong>Páginas: </strong>';
            
            echo '<select name="pagina" onChange=this.form.submit()>';
            echo '<option>'.$pagina.'</option>';
            
            for ($i=1;$i<=$total_paginas;$i++)
            {
                if ($i<>$pagina)
                {
                echo '<option>'.$i.'</option>';
                }
            }

            echo '</select>';
            echo '</div>';
            echo'</form>';
            ?>
			  
			</div>
		  <div class="table">
				
                                <form method = "POST" action = "operacion.php">
                                 <table class="listing form" cellpadding="0" cellspacing="0">
					<tr>
						<th class="full" colspan="2">Modificacion de Propiedad</th>
					</tr>
					<tr>
						<td class="first" width="172"><strong>ID</strong></td>
						<td class="last"><input type="text" name="idpropiedad"/></td>

                                         </tr>

				</table>
                                                <script type="text/javascript">
                                                function borrar(id){
                                                    if(confirm("Esta seguro de borrar esta propiedad?")){
                                                    window.location="operacion.php";
                                                    }
                                                    else {
                                                         return (false);
                                                         }
                                                }
                                                </script>

                                    <br><input type="submit" value="Borrar" name="boton" onclick="return borrar(idpropiedad);"/>
                                                <input type="submit" value="Modificar" name="boton"/>

                                                </form>

	        <p>&nbsp;</p>

                  <a href="nuevapropiedad.php"><h4>Agregar nueva propiedad</h4></a>

                  </div>
		</div>

	</div>
	<div id="footer"></div>
</div>


</body>
</html>
